package 题目集.动态规划;

import java.io.*;
import java.util.StringTokenizer;

public class 三角形的最大路径和 {
    static int[][] tree = new int[102][103];  //不要0位置
    static int[][] dp = new int[102][103];
    static int n;

    public static void main(String[] args) {
        Reader sc = new Reader();
        n = sc.nextInt();
        for (int i = n; i > 0; i--) {
            for (int j = 1; j <= n-i+1; j++) {
                tree[i][j] = sc.nextInt();
            }
        }
        int dfs = dpFun(n);
        System.out.println(dfs);
    }

    public static int dfs(int row, int col) {
        if (row == n) {
            return tree[row][col];
        }

        int left = dfs(row + 1, col);
        int right = dfs(row + 1, col + 1);
        dp[row][col] = Math.max(left, right) + tree[row][col];
        return dp[row][col];
    }

    public static int dpFun(int n) {
        int[][] dp = new int[n + 2][n + 2];
        for (int i = n; i > 0; i--) {
            dp[1][i] = tree[1][i];
        }
        for (int i = 2; i <= n; i++) {
            for (int j = 1; j <= n-i+1; j++) {
                dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j + 1]) + tree[i][j];
            }
        }
        return dp[n][1];
    }


    static class Reader {
        private PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }

        public void clear() {
            tokenizer = new StringTokenizer("");
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
//    public BigInteger nextBigInt() {
//        return new BigInteger(next());
//    }
    }

}
